﻿using System;
using System.Collections.Generic;
using System.Web;
using Org.BouncyCastle.Asn1.Ocsp;

/// <summary>
///ContentPage 的摘要说明
///调用方法//增加信息时[pager]
/// </summary>
public class ContentPage
{
	public ContentPage()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}
    public static string[] StringSplit(string strSource, string strSplit)
    {
        string[] strtmp = new string[1];
        int index = strSource.IndexOf(strSplit, 0);
        if (index < 0)
        {
            strtmp[0] = strSource;
            return strtmp;
        }
        else
        {
            strtmp[0] = strSource.Substring(0, index);
            return StringSplit(strSource.Substring(index + strSplit.Length), strSplit, strtmp);
        }
    }
    public static string[] StringSplit(string strSource, string strSplit, string[] attachArray)
    {
        string[] strtmp = new string[attachArray.Length + 1];
        attachArray.CopyTo(strtmp, 0);

        int index = strSource.IndexOf(strSplit, 0);
        if (index < 0)
        {
            strtmp[attachArray.Length] = strSource;
            return strtmp;
        }
        else
        {
            strtmp[attachArray.Length] = strSource.Substring(0, index);
            return StringSplit(strSource.Substring(index + strSplit.Length), strSplit, strtmp);
        }
    }
    public static string content(string aa, string condition)
    {
      
        string[] contentArray = StringSplit(aa, "[pager]");

        string[] seperator = { "[pager]" };
        int pageCount = aa.Split(seperator, StringSplitOptions.None).Length;//总页数

        int stat;
        int start;
        int stop;
        int i;

        stat = 0;
        start = 0;
        stop = 0;
        i = 0;

        string contentPageStr = "";
        //获取当前页数
        string pa =HttpContext.Current.Request.QueryString["page"];
        if (pa == "" || pa == null)
        {
            pa = "1";
        }
        int pp = int.Parse(pa);

        string str = "";

        if (condition.IndexOf("?") > -1)
            str = "&page=";
        else
            str = "?page=";


        //分页部分（这里就简单多了）
        string html = "";//定义分页代码变量
        if (pageCount > 1)//当页数大于1的时候我们显示页数
        {
            if (pp != 1)
                html += "<a href=" + condition + str + (pp - 1) + ">[上一页]</a>";
            for (i = 1; i <= pageCount; i++)
            {
                if (i == pp)//如果是当前页，加粗显示
                    html += "<b>[" + i + "]</b> ";
                else
                    html += "<a href=" + condition + str + i + ">[" + i + "]</a> ";
            }
            if (pp + 1 <= pageCount)//显示下一页，方便浏览
                html += "<a href=" + condition + str + (pp + 1) + ">[下一页]</a></p>";

        }

        return contentArray[pp - 1].ToString() + "<br /><center>" + html.ToString() + "</center>";
    }
    //==========分页End
}
